package com.inspur.sc.springboot.service.impl;

import com.inspur.sc.springboot.dao.SysMenuDao;
import com.inspur.sc.springboot.entity.SysMenu;
import com.inspur.sc.springboot.service.SysMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
public class SysMenuServiceImpl implements SysMenuService {

    @Autowired
    private SysMenuDao menuDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SysMenu sysMenu) {
        try{
            menuDao.save(sysMenu);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(Integer id) {
        try {
            menuDao.deleteById(id);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    @Override
    public SysMenu findSysMenuById(Integer id) {
        return menuDao.findById(id).get();
    }

    @Override
    public List<SysMenu> findSysMenuByUId(Integer uid) {
        return menuDao.findSysMenuByUserId(uid);
    }

    @Override
    public List<SysMenu> findSysMenuIsParent() {
        return menuDao.findSysMenuIsParent();
    }

    @Override
    public List<SysMenu> findAll() {
        return menuDao.findAll();
    }
}
